# Tools etc.
RM := rm -f
-GDB := gdb
INCS := -I. -I-
DEFS :=
-LDFLAGS :=
-CFLAGS += -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format
-CFLAGS += -Wmissing-prototypes -pipe
# What object files need building for the program
OBJS := mbootpack.o buildimage.o
DEPS = .*.d
mbootpack: $(OBJS)
- $(HOSTCC) -o $@ $(filter-out %.a, $^)
+ $(HOSTCC) $(HOSTCFLAGS) -o $@ $(filter-out %.a, $^)
.PHONY: clean
clean:
$(RM) mbootpack *.o $(DEPS) bootsect setup bzimage_header.c bin2c
bootsect: bootsect.S
- $(CC) $(CFLAGS) $(INCS) $(DEFS) -D__MB_ASM -c bootsect.S -o bootsect.o
+ $(CC) -m32 $(INCS) $(DEFS) -D__MB_ASM -c bootsect.S -o bootsect.o
$(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary bootsect.o -o $@
setup: setup.S
- $(CC) $(CFLAGS) $(INCS) $(DEFS) -D__MB_ASM -c setup.S -o setup.o
+ $(CC) -m32 $(INCS) $(DEFS) -D__MB_ASM -c setup.S -o setup.o
$(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary setup.o -o $@
bin2c: bin2c.o
- $(HOSTCC) -o $@ $^
+ $(HOSTCC) $(HOSTCFLAGS) -o $@ $^
bzimage_header.c: bootsect setup bin2c
./bin2c -n 8 -b1 -a bzimage_bootsect bootsect > bzimage_header.c
buildimage.c: bzimage_header.c
@
-%.o: %.S
- $(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
-
%.o: %.c
- $(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
+ $(HOSTCC) $(DEPFLAGS) $(HOSTCFLAGS) $(INCS) $(DEFS) -c $< -o $@
.PRECIOUS: $(OBJS) $(OBJS:.o=.c) $(DEPS)
.SUFFIXES:
*
*/
-
-
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
/* Bring in the bzImage boot sector and setup code */
#include "bzimage_header.c"
+#define _p(x) ((void *)(unsigned long)(x))
+
address_t place_mbi(long int size)
/* Find space at the top of *low* memory for the MBI and associated red tape */
{
address_t start;
start = 0xa000 - size;
if (start < 0x9000 + sizeof(bzimage_bootsect) + sizeof(bzimage_setup)) {
- printf("Fatal: command-lines too long: need %i, have %i bytes\n",
+ printf("Fatal: command-lines too long: need %ld, have %ld bytes\n",
size,
- 0x1000 - (sizeof(bzimage_bootsect) + sizeof(bzimage_setup)));
- exit(1);
+ 0x1000L - (sizeof(bzimage_bootsect) + sizeof(bzimage_setup)));
+ exit(1);
}
if (!quiet) {
printf("Placed MBI and strings (%p+%p)\n",
- start, size);
+ _p(start), _p(size));
}
return start;
}
/* Patch the kernel and mbi addresses into the setup code */
*(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) = eswap(entry);
*(address_t *)(bzimage_setup + BZ_MBI_OFFSET) = eswap(mbi);
- if (!quiet) printf("Kernel entry is %p, MBI is %p.\n", entry, mbi);
+ if (!quiet) printf("Kernel entry is %p, MBI is %p.\n",_p(entry), _p(mbi));
/* Write out header and trampoline */
if (fseek(fp, 0, SEEK_SET) < 0) {
exit(1);
}
- if (!quiet) printf("Wrote bzImage header: %i + %i bytes.\n",
- sizeof(bzimage_bootsect), sizeof(bzimage_setup));
+ if (!quiet) printf("Wrote bzImage header: %ld + %ld bytes.\n",
+ (long)sizeof(bzimage_bootsect),
+ (long)sizeof(bzimage_setup));
/* Sorted list of sections below 1MB: write them out */
for (s = sections, i = 0; s; s = s->next) {
exit(1);
}
+#define _p(x) ((void *)(unsigned long)(x))
static void place_kernel_section(address_t start, long int size)
/* Place the kernel in memory, checking for the memory hole. */
/* Above the memory hole: easy */
next_free_space = MAX(next_free_space, start + size);
if (!quiet) {
- printf("Placed kernel section (%p+%p)\n", start, size);
+ printf("Placed kernel section (%p+%p)\n",
+ _p(start), _p(size));
}
return;
}
if (start >= MEM_HOLE_START) {
/* In the memory hole. Not so good */
printf("Fatal: kernel load address (%p) is in the memory hole.\n",
- start);
+ _p(start));
exit(1);
}
if (start + size > MEM_HOLE_START) {
/* Too big for low memory */
printf("Fatal: kernel (%p+%p) runs into the memory hole.\n",
- start, size);
+ _p(start), _p(size));
exit(1);
}
next_free_space = MAX(next_free_space, start + size);
if (!quiet) {
- printf("Placed kernel section (%p+%p)\n", start, size);
+ printf("Placed kernel section (%p+%p)\n", _p(start), _p(size));
}
}
if (!quiet) {
printf("Placed section (%p+%p), align=%p\n",
- start, size, align);
+ _p(start), _p(size), _p(align));
}
return start;
}
-
-
static address_t load_kernel(const char *filename)
/* Load an elf32/multiboot kernel from this file
* Returns the entry address for the kernel. */
size = loadsize;
if (loadsize > size) {
- printf("Fatal: can't load %i bytes of kernel into %i bytes "
+ printf("Fatal: can't load %ld bytes of kernel into %ld bytes "
"of memory.\n", loadsize, size);
exit(1);
}
}
-
-
int main(int argc, char **argv)
{
char *buffer, *imagename, *command_line, *p;
struct mod_list *modp;
address_t start, kernel_entry;
long int size, mod_command_line_space, command_line_len;
- int modules, opt, mbi_reloc_offset, make_multiboot;
+ int modules, opt, mbi_reloc_offset;
static const char short_options[] = "hc:m:o:qM";
static const struct option options[] = {